﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Giaiphongmatbang.DataModel;

namespace Giaiphongmatbang.BLL
{
    public class InventoryHouseRepository
    {
        private QLGPMBEntities data = new QLGPMBEntities();

        public IEnumerable<InventoryHouse> GetAll(int pageSize, int pageNumber, ref int totalRow)
        {
            var results = from p in data.InventoryHouses
                          select p;
            totalRow = results.Count();
            return results.OrderBy(p => p.ProjectID).Skip((pageNumber - 1) * pageSize).Take(pageSize);
        }

        public IEnumerable<InventoryHouse> GetByProjectID(int ID)
        {
            var results = from p in data.InventoryHouses
                          where p.ProjectID == ID
                          select p;
            return results;
        }

        public IEnumerable<InventoryHouse> GetByCMND(string cmnd)
        {
            var results = from p in data.InventoryHouses
                          where p.CMND == cmnd
                          select p;
            return results;
        }

        public IEnumerable<InventoryHouse> GetByHouseID(int ID)
        {
            var results = from p in data.InventoryHouses
                          where p.HouseID == ID
                          select p;
            return results;
        }

        public void Insert(InventoryHouse ih)
        {
            data.AddToInventoryHouses(ih);
        }

        //public void DeleteByID(int id)
        //{
        //    var obj = GetByID(id).FirstOrDefault();
        //    data.DeleteObject(obj);
        //}

        public void Save()
        {
            data.SaveChanges();
        }
    }
}